//
//  SSSPersonalGoodPointViewController.m
//  SSSMerchant
//
//  Created by xnxin on 2017/3/22.
//  Copyright (c) 2017 xnxin. All rights reserved.
//

#import "SSSPersonalGoodPointViewController.h"
#import "UIButtonAdditions.h"
#import "XHUIHelper.h"
#import "SSSPersonalGoodsPointsCellModel.h"

@interface SSSPersonalGoodPointViewController ()

@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) QMUIButton *currentGoodsPointButton;
@property (nonatomic, strong) UILabel *totalGoodPointLabel;

@property (nonatomic, assign) NSInteger currentGoodPoints;
@property (nonatomic, assign) NSInteger totalGoodPoints;
@end

@implementation SSSPersonalGoodPointViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.tableHeaderView = self.headerView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

    self.tableView.left = 15;
    self.tableView.width = self.view.width - 30;

    self.currentGoodPoints = 0;
    self.totalGoodPoints = 0;
}

#pragma mark - getter

- (NSArray<NSString *> *)nibNameArray {
    return @[@"SSSPersonalGoodsPointsCell"];
}
- (UIView *)headerView {
    if(!_headerView) {

        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH, 65)];
        _currentGoodsPointButton = [QMUIButton new];
        _currentGoodsPointButton.titleLabel.font = [UIFont systemFontOfSize:12];
        _currentGoodsPointButton.normalImage = [UIImage imageNamed:@"icon_nowpoint"];

        [_headerView addSubview:_currentGoodsPointButton];

        _totalGoodPointLabel = [UILabel new];
        _totalGoodPointLabel.font = [UIFont systemFontOfSize:12];
        _totalGoodPointLabel.textColor = [UIColor colorWithHex:@"BBBBBB"];

        [_headerView addSubview:_totalGoodPointLabel];

        UIView *line = [XHUIHelper sepreateLineWithY:64.5];
        [_headerView addSubview:line];
        _headerView.clipsToBounds = true;
    }

    return _headerView;
}

- (NSArray<__kindof XHBaseTableViewCellModel *> *)modelArray {

    SSSPersonalGoodsPointsCellModel *model = [SSSPersonalGoodsPointsCellModel new];
    model.date = [NSDate date];

    return @[model, model, model];
}
#pragma mark - UITableView


#pragma mark -

- (void)setCurrentGoodPoints:(NSInteger)currentGoodPoints {

    _currentGoodPoints = currentGoodPoints;
    self.currentGoodsPointButton.normalTitle = [NSString stringWithFormat:@" 当前善点 %ld",(long)currentGoodPoints];
    [self.currentGoodsPointButton sizeToFit];
    self.currentGoodsPointButton.centerX = self.headerView.width/2;
    self.currentGoodsPointButton.top = 15;
}

- (void)setTotalGoodPoints:(NSInteger)totalGoodPoints {
    _totalGoodPoints = totalGoodPoints;

    self.totalGoodPointLabel.text = [NSString stringWithFormat:@"(累计善点%ld)", (long)totalGoodPoints];
    [self.totalGoodPointLabel sizeToFit];
    self.totalGoodPointLabel.centerX = self.headerView.width/2;
    self.totalGoodPointLabel.top = self.currentGoodsPointButton.bottom + 8;
}

@end
